﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;

namespace YouHP.Pages.Profile
{
    public class DiseaseSystem : YouHP.Pages.Profile.ProfileBasePage
    {
        private const int SymptomBaseHeight = 110;
        private const int SymptomYGap = 30;
        protected int SymptomGraphHeight = SymptomBaseHeight + SymptomYGap;

        private const int WeightbaseHeight = 320;
        private const int WeightYGap = 30;
        protected int WeightGraphHeight = WeightbaseHeight;

        private const int TreatmentBaseHeight = 110;
        private const int TreatmentYGap = 30;
        protected int TreatmentGraphHeight = TreatmentBaseHeight + TreatmentYGap;

        protected int ShowMode = Constants.DEFAULTMODE;

        public override void InitPage()
        {
            base.InitPage();

        }

        protected override void ShowPage()
        {


            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected void HandleCommon()
        {
            //如果是本人登录此页面，将留言设置为已读
            if (UserData.Id == ProfileData.Id)
            {
                CommentBLL.Instance.UpdateCommentState(ProfileData.Id, 1,0);
            }
            this.SetTitle(ProfileData.UserName + "的病情系统");
            this.AddCommonJS();
            this.AddLinkCss("/support/alpha/css/DiseaseSystem.css");
            this.GetMsgCount();

        }

        protected void HandlePost()
        {

        }

        protected int GraphWidth = 800;

        protected string GraphGeneralPath;
        protected string GraphIndicatorPath;
        protected string GraphSymptomPath;
        protected string GraphTreatmentPath;

        protected List<CommentInfo> CommentDataList;
        protected int PageIndex;
        protected int DataCount;
        protected int PageCount;
        protected string PagingString;

        protected void HandleGet()
        {
            ShowMode = RequestTools.GetQueryInt("showMode", Constants.DEFAULTMODE);

            //PrData = PatientBLL.Instance.GetPatientRecordInfo(ProfileData.Id);
            CommentDataList = CommentBLL.Instance.GetCommentList(10, PageIndex, ProfileData.Id, out DataCount);

            //利用症状个数以及症状组数来计算flash高度
            int groupCount = 1;
            List<SymptomHistoryInfo> CurrentSymptomList = PatientSymptomBLL.Instance.GetCurrentSymptomList(PrData.Id);
            for (int i = 0; i < CurrentSymptomList.Count; i++)
            {
                if (CurrentSymptomList[i].Type == Constants.SECOND_SYMPTOM)
                {
                    groupCount++;
                    break;  //发现次要症状，则跳出循环
                }
            }

            if (CurrentSymptomList != null)
            {
                SymptomGraphHeight += (CurrentSymptomList.Count) * SymptomYGap + (int)((groupCount - 1) * SymptomYGap * 1.5);
            }

            //利用治疗个数来计算flash高度
            List<TreatmentHistoryInfo> CurrentTreatmentList = PatientTreatmentBLL.Instance.GetAllCurTreatments(PrData.Id);
            if (CurrentTreatmentList != null)
            {
                TreatmentGraphHeight += (CurrentTreatmentList.Count) * TreatmentYGap + (int)(TreatmentYGap * 1.5);
            }
        }
    }
}